# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Renato Silva <br.renatosilva@gmail.com>

_realname=drmingw
pkgbase="mingw-w64-${_realname}-git"
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
pkgver=r513.df06575
pkgrel=1
pkgdesc="Just-in-Time (JIT) debugger (mingw-w64)"
arch=('any')
license=(LGPL2.1)
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=(${MINGW_PACKAGE_PREFIX}-discount
             ${MINGW_PACKAGE_PREFIX}-cmake
             ${MINGW_PACKAGE_PREFIX}-gcc
             git)
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")
url='https://github.com/jrfonseca/drmingw'
source=("${_realname}"::"git+https://github.com/jrfonseca/drmingw.git"
        import-libs.patch
        install-files.patch)
options=(!strip staticlibs)
sha256sums=('SKIP'
            'af7a781e65d8b0f7929089f0fab0b9eacd55a01edd7ed21f465a2fe4727d46eb'
            '884c0e5aa04523a1c1d44fff5c0295dcdc855f7a0af3890af945bfc44acf4b35')

pkgver() {
  cd "$srcdir/$_realname"
  printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

prepare() {
  cd ${_realname}
  #patch -p1 -i ${srcdir}/import-libs.patch
  patch -p1 -i ${srcdir}/install-files.patch
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p ${srcdir}/build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    ../${_realname}

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR=${pkgdir} -j1 install

  # License files
  cd "${pkgdir}${MINGW_PREFIX}/share"
  mkdir -p licenses/${_realname}
  mv doc/${_realname}/LICENSE* licenses/${_realname}

  # Readme
  cd "${pkgdir}${MINGW_PREFIX}/share/doc/${_realname}"
  markdown README.md > README.html
  rm README.md
}
